﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SXICE.Core.Models
{
    /// <summary>
    /// 返回分页结果
    /// </summary>
    public class ReturnPageListResult<T> : ReturnResult<List<T>>
    {
        public ReturnPageListResult() : base() { }

        public ReturnPageListResult(List<T> result, int total) : base(result)
        {
            this.Total = total;
        }

        public ReturnPageListResult(int errorCode, string errorMessage) : base(errorCode, errorMessage) { }

        /// <summary>
        /// 原型
        /// </summary>
        private readonly static ReturnPageListResult<T> prototype = new ReturnPageListResult<T>();

        /// <summary>
        /// 总条数
        /// </summary>
        public int Total { set; get; }

        /// <summary>
        /// 获取结果(成功）
        /// </summary>
        /// <param name="list">数据列表</param>
        /// <param name="total">总数</param>
        /// <returns>结果</returns>
        public static ReturnPageListResult<T> GetResult(List<T> list, int total)
        {
            var proto = (ReturnPageListResult<T>)prototype.Clone();
            proto.Success = true;
            proto.Result = list;
            proto.Total = total;
            return proto;
        }

        /// <summary>
        /// 获取结果
        /// </summary>
        /// <param name="errorCode">错误码</param>
        /// <param name="errorMessage">错误消息</param>
        /// <returns>结果</returns>
        public new static ReturnPageListResult<T> GetResult(int errorCode, string errorMessage)
        {
            var proto = (ReturnPageListResult<T>)prototype.Clone();
            proto.ErrorCode = errorCode;
            proto.ErrorMessage = errorMessage;
            proto.Success = false;
            return proto;
        }
    }
}